﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI.WebControls;
using System.Web.Security;
using System.Web.UI;


namespace fcwms.Common
{
    public class MessageBox
    {

        #region 显示消息提示对话框
        /// <summary>
        /// 显示消息提示对话框
        /// </summary>
        /// <param name="page">当前页面指针，一般为this</param>
        /// <param name="msg">提示信息</param>
        /// 调用: MessageBox.Show(this,"123");
        public static void Show(System.Web.UI.Page page, string msg)
        {
            // page.RegisterStartupScript("message", "<script language='javascript' defer>alert('" + msg.ToString() + "');</script>");
            page.ClientScript.RegisterStartupScript(page.GetType(), "message", "<script language='javascript' defer>alert('" + msg.ToString() + "');</script>");
        }

        #endregion

        #region 控件点击 消息确认提示框

        /// <summary>
        /// 控件点击 消息确认提示框
        /// </summary>
        /// <param name="page">当前页面指针，一般为this</param>
        /// <param name="msg">提示信息</param>
        /// 调用：MessageBox.ShowConfirm(Button1,"123");
        public static void ShowConfirm(System.Web.UI.WebControls.WebControl Control, string msg)
        {
            // Control.Attributes.Add("onClick","if (!window.confirm('"+msg+"')){return false;}");
            Control.Attributes.Add("onclick", "return confirm('" + msg + "');");
        }
        #endregion

        #region 显示消息提示对话框，并进行页面跳转
        /// <summary>
        /// 显示消息提示对话框，并进行页面跳转
        /// </summary>
        /// <param name="page">当前页面指针，一般为this</param>
        /// <param name="msg">提示信息</param>
        /// <param name="url">跳转的目标URL</param>
        /// 调用： MessageBox.ShowAndRedirect(this, "123", "123.aspx");
        public static void ShowAndRedirect(System.Web.UI.Page page, string msg, string url)
        {
            StringBuilder Builder = new StringBuilder();
            Builder.Append("<script language='javascript' defer>");
            Builder.AppendFormat("alert('{0}');", msg);
            Builder.AppendFormat("location.href='{0}'", url);
            Builder.Append("</script>");
            //page.RegisterStartupScript("message", Builder.ToString());
            page.ClientScript.RegisterStartupScript(page.GetType(), "message", Builder.ToString());

        }


        public static void ShowAndRedirect(System.Web.UI.Page page, string msg, string url, bool top)
        {
            StringBuilder Builder = new StringBuilder();
            Builder.Append("<script language='javascript' defer>");
            Builder.AppendFormat("alert('{0}');", msg);
            if (top == true)
            {
                Builder.AppendFormat("top.location.href='{0}'", url);
            }
            else
            {
                Builder.AppendFormat("location.href='{0}'", url);
            }
            Builder.Append("</script>");
            // page.RegisterStartupScript("message", Builder.ToString());
            page.ClientScript.RegisterStartupScript(page.GetType(), "message", Builder.ToString());

        }

        #endregion

        #region 输出自定义脚本信息
        /// <summary>
        /// 输出自定义脚本信息
        /// </summary>
        /// <param name="page">当前页面指针，一般为this</param>
        /// <param name="script">输出脚本</param>
        public static void ResponseScript(System.Web.UI.Page page, string script)
        {
            //page.RegisterStartupScript("message", "<script language='javascript' defer>" + script + "</script>");
            page.ClientScript.RegisterStartupScript(page.GetType(), "message", "<script language='javascript' defer>" + script + "</script>");
        }

        #endregion

        #region 弹出对话框

        /// <summary>
        ///说明: show 用来在客户端弹出对话框
        ///参数：TxtMessage 为对话框中显示的内容
        /// </summary>
        ///调用：Response.Write(MessageBox("信息"));  
        public static string show(string TxtMessage)
        {
            string str;
            str = "<script language = javascript>alert('" + TxtMessage + "')</script>";
            return str;

        }

        #endregion

        #region 弹出对话框，关闭对话框返回指定页

        /// <summary>
        ///说明: show 用来在客户端弹出对话框，关闭对话框返回指定页
        ///参数：TxtMessage 为对话框中显示的内容
        ///参数：Url 为对话框关闭后跳到的指定页
        /// </summary>
        ///调用：Response.Write(MessageBox("信息","123.aspx"));  
        public static string show(string TxtMessage, string Url)
        {
            string str;
            str = "<script language = javascript>alert('" + TxtMessage + "');location = '" + Url + "';</script>";
            return str;
        }

        #endregion

        #region 弹出对话框，关闭对话框返回原页

        /// <summary>
        ///说明: show 用来在客户端弹出对话框，关闭对话框返回原页
        ///参数：TxtMessage 为对话框中显示的内容
        /// </summary>
        ///调用：Response.Write(MessageBox("信息"));  
        public static string refresh(string TxtMessage)
        {
            string str;
            str = "<script language = javascript>alert('" + TxtMessage + "');location ='javascript:history.go(-1)';</script>";
            return str;
        }

        #endregion

        #region JS提示============================================

        /// <summary>
        /// 添加编辑删除提示
        /// </summary>
        /// <param name="msgtitle">提示文字</param>
        /// <param name="url">返回地址</param>
        /// <param name="msgcss">CSS样式</param>
        public static void Jscript(System.Web.UI.Page page, string msgtitle, string url, string msgcss)
        {
            string msbox = "parent.jsprint(\"" + msgtitle + "\", \"" + url + "\", \"" + msgcss + "\")";
            page.ClientScript.RegisterClientScriptBlock(page.GetType(), "JsPrint", msbox, true);
        }

        /// <summary>
        /// 带回传函数的添加编辑删除提示
        /// </summary>
        /// <param name="msgtitle">提示文字</param>
        /// <param name="url">返回地址</param>
        /// <param name="msgcss">CSS样式</param>
        /// <param name="callback">JS回调函数</param>
        public static void Jscript(System.Web.UI.Page page, string msgtitle, string url, string msgcss, string callback)
        {
            string msbox = "parent.jsprint(\"" + msgtitle + "\", \"" + url + "\", \"" + msgcss + "\", " + callback + ")";
            page.ClientScript.RegisterClientScriptBlock(page.GetType(), "JsPrint", msbox, true);
        }
        #endregion

        //#region 枚举==============================================

        ///// <summary>
        ///// 统一管理操作枚举
        ///// </summary>
        //public enum ActionEnum
        //{
        //    /// <summary>
        //    /// 所有
        //    /// </summary>
        //    All,
        //    /// <summary>
        //    /// 查看
        //    /// </summary>
        //    View,
        //    /// <summary>
        //    /// 添加
        //    /// </summary>
        //    Add,
        //    /// <summary>
        //    /// 修改
        //    /// </summary>
        //    Edit,
        //    /// <summary>
        //    /// 删除
        //    /// </summary>
        //    Delete
        //}

        ///// <summary>
        ///// 属性类型枚举
        ///// </summary>
        //public enum AttributeEnum
        //{
        //    /// <summary>
        //    /// 输入框
        //    /// </summary>
        //    Text,
        //    /// <summary>
        //    /// 下拉框
        //    /// </summary>
        //    Select,
        //    /// <summary>
        //    /// 单选框
        //    /// </summary>
        //    Radio,
        //    /// <summary>
        //    /// 复选框
        //    /// </summary>
        //    CheckBox
        //}
        //#endregion

    }

}
